package com.ssmdemo.handel;

import com.ssmdemo.pojo.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalException {

    @ExceptionHandler(value = BusinessException.class)//只要出现这类异常或这个类子类异常就调用该方法
    @ResponseBody
    public String businessException(BusinessException e){

        log.error("业务异常",e);

        return e.getMsg();
    }

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public String systemException(Exception e){
        log.error("系统异常",e);
        return "系统正在维护.......";
    }

}
